package com.noahplat.user.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.user.pojo.Account;
import com.noahplat.user.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 账套相关操作
 *
 * @author 李东
 * @version 1.0.0
 * @Date: 2021/3/1 15:10
 **/

@RestController
@RequestMapping("/api/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    /**
     * 查询账套列表
     *
     * @author 李东
     * @version 1.0.0
     * @Date: 2021/3/1 15:10
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:AccountControllerr:findAccountList')")
    @GetMapping("/findAccountList")
    public Result findAccountList() {
        return accountService.findAccountList();
    }

    /**
     * 通过Id查询账套信息
     *
     * @author 李东
     * @version 1.0.0
     * @Date: 2021/3/1 15:10
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:AccountController:findAccInfoById')")
    @GetMapping("/findAccInfoById")
    public Result<Account> findAccInfoById(Long id) {
        return accountService.findAccInfoById(id);
    }

    /**
     * 分页查询账套信息
     * @param status
     * @param page
     * @param limit
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:AccountController:getAccount')")
    @GetMapping("/getAccount")
    public Result getAccount(@RequestParam String status, @RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit){
        return accountService.getAccount(status, page, limit);
    }

    /**
     * 新增账套信息
     * @param account
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:AccountController:addAccount')")
    @PostMapping("/addAccount")
    public Result addAccount(@RequestBody Account account){
        return accountService.addAccount(account);
    }

    /**
     * 修改账套信息
     * @param account
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:AccountController:updateAccount')")
    @PutMapping("/updateAccount")
    public Result updateAccount(@RequestBody Account account){
        return accountService.updateAccount(account);
    }

    /**
     * 不分页获取账套信息
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:AccountController:getAccounts')")
    @GetMapping("/getAccounts")
    public Result getAccounts(){
        return accountService.getAccounts();
    }
}
